ABC270 C - Simple path
提出
code: python
from collections import defaultdict
from collections import deque
n, x, y = list(map(int, input().split()))
print(uv)
graph = defaultdict(list)
for i in uv:
print(graph)
que = deque()
que.append(x)
visited = {2}
path = set()
ans = []
while que:
d = que.popleft()
if not i in visited:
que.append(i)
visited.add(i)
print(ans)
解答
code: python
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
n, x, y = map(int, input().split())
d = defaultdict(list)
for u, v in uv:
# # print(d)
# defaultdict(<class 'list'>, {1: 2, 3, 2: 1, 3: 1, 4, 5, 4: 3, 5: 3}) def dfs(now, prev):
if now == y:
print(*ans)
exit()
# 3 continue の行き先は... -> ans.pop() if next == prev:
continue
ans.append(next)
# print(ans)
# print(next, now)
# 1 2
# 3 1
# 4 3
# 5 3
dfs(next, now)
ans.pop()
dfs(x, 0)
テーマ
メモ
提出
code: python
from collections import defaultdict
from collections import deque
n, x, y = map(int, input().split())
d = defaultdict(list)
for u, v in uv:
q = deque()
visited = set()
path = []
q.append(x)
while len(q):
next = q.popleft()
if next in visited:
continue
else:
visited.add(next)
path.append(next)
path.append(y)
break
q.append(p)
print(" ".join(map(str, path)))